﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace PacCraft
{
    class Camera
    {
        public Vector2 position;
        public float orientation;
        public BasicEffect basicEffect;

        public int vue = 0;

        public Camera(GraphicsDeviceManager graphics)
        {
            basicEffect = new BasicEffect(graphics.GraphicsDevice);
            basicEffect.World = Matrix.CreateTranslation(new Vector3(0, 0, 0));
            
            basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(50), 800f / 600f, 0.1f, 100f);
            basicEffect.VertexColorEnabled = true;
        }

        public BasicEffect getCamera()
        {
            Vector3 cameraPosition;
            Vector3 cameraTarget;
            if (vue == 0)
            {
                cameraPosition = new Vector3(position.X, 2.9f, position.Y);
                cameraTarget = new Vector3(cameraPosition.X + 10 * (float)Math.Cos(orientation), 3, cameraPosition.Z + 10 * (float)Math.Sin(orientation));
            }
            else
            {
                cameraPosition = new Vector3(position.X - (float)Math.Cos(orientation), 4f, position.Y - (float)Math.Sin(orientation));
                cameraTarget = new Vector3(position.X + (float)Math.Cos(orientation) * 0.5f, 2f, position.Y + (float)Math.Sin(orientation) * 0.5f);
            }
            basicEffect.View = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.UnitY);
            basicEffect.VertexColorEnabled = true;
            basicEffect.World = Matrix.Identity;

            return basicEffect;
        }
    }
}
